package com.luo.testtouch.publicview;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.os.Message;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

/**
 * 
 * 自定义View
 * 
 * 做笔记功能
 */
public class NoteView extends View
{
	private static final String TAG = "note_view";
	private static final String TAG2 = "note_view2";

	/**
	 * 定义画笔模式
	 */
	public static final int MODE_ERASER = 0;
	public static final int MODE_PENCIL = 1;
	public static final int MODE_HIGHLIGHTER = 2;//荧光笔
	/**
	 * 画笔模式模式
	 */
	private int mode;

	/**
	 * 画笔宽度
	 */
	public static final int PEN_WID_4 = 4;
	public static final int PEN_WID_8 = 8;
	public static final int PEN_WID_16 = 16;

	private static final float MINP = 0.25f;
	private static final float MAXP = 0.75f;

	/*** 背景 ，也是保存之前画的轨迹
	 * 
	 */
	private Bitmap mBitmap;
	private Canvas mCanvas;

	/** 画图路径 */
	private Path mPath;
	/**
	 * 画bitmap 用的Paint
	 */
	private Paint mBitmapPaint;

	/** 笔记用 **/
	private Paint mPaint;

	private Context mContext2;
	/**
	 * 之前保存的笔记
	 */
	private Bitmap savedBitmMap;
	/**
	 * 之前做的笔记
	 */
	// private String filePath;

	/** 是否保存笔记 true保存 */
	// private boolean mSaveFlag = false;
	/*** 用于橡皮 **/
	private Paint mPaint2;
	/**
	 * 标示 最后清空长方形框（用于橡皮模式）
	 */
	private boolean mLast;
	 /**
	  * 笔记保存路径
	  */
	private String mfilePath;

	/**
	 * 
	 */
	private Bitmap mLoadedBitmap;

	
//	/**
//	 * 
//	 * @param c
//	 */
//	public NoteView(Context c)
//	{
//		super(c);
//		mContext2 = c;
//		flag_inti = false;
//
//		// ////////
//		mBitmapPaint = new Paint(Paint.DITHER_FLAG);
//		mPath = new Path();
//		mCanvas = new Canvas();
//		
//		intiPaint();
//		
//		needSave = false;
//		
//		//20120702 ，统一颜色
//		mdefaultColor = ReciteUitl.PENCIL_COLOR ;
//
//	}

	/**
	 * 布局文件用g
	 * 
	 * @param context
	 * @param attrs
	 */
	public NoteView(Context context, AttributeSet attrs)
	{
		super(context, attrs);

		this.mContext2 = context;
		flag_inti = false;

		// intiVar(context);
		mBitmapPaint = new Paint(Paint.DITHER_FLAG);
		mPath = new Path();
//		mCanvas = new Canvas();不知道画布大小？
		
		
		needSave = false;
		intiPaint();
		
		////0601
		inti();
		
		//20120702 ，统一颜色
		mdefaultColor = GUitl.PENCIL_COLOR ;

	}

	/**
	 * 
	 * desp：有关尺寸的设置
	 *
	 * 一次
	 *@param c
	 */
	private void intiVar(Context c)
	{
		@SuppressWarnings("unused")
		int g_width = getWidth();
		int g_height = getHeight();

		mAdjustment = 200;
		// Rect
		mRect = new Rect();
		mRect.set(0, 0, 0, 0);

		mRectRefresh = new Rect();
		mRectRefresh.set(0, 0, 0, 0);

//		load();
		
		
		mBitmap = Bitmap.createBitmap(g_width, g_height,
				Bitmap.Config.ARGB_4444);
		mCanvas = new Canvas(mBitmap);

	}

	/**
	 * 初始化 做笔记paint
	 */
	private void intiPaint()
	{
		// 橡皮擦用
		mPaint2 = new Paint();

		// ****** 画笔用mPaint
		mPaint = new Paint();

		// 抗锯齿
		mPaint.setAntiAlias(true);
		mPaint.setDither(true);

		mPaint.setColor(GUitl.PENCIL_COLOR);
		// 线条样式？？、？
		mPaint.setStyle(Paint.Style.STROKE);
		mPaint.setStrokeJoin(Paint.Join.ROUND);
		// 线帽样式
		mPaint.setStrokeCap(Paint.Cap.ROUND);
		// 线的宽度
		mPaint.setStrokeWidth(mPenWidth);
	}

	@Override
	protected void onLayout(boolean changed, int left, int top, int right,
			int bottom)
	{
		super.onLayout(changed, left, top, right, bottom);
	}

	/**
	 * 测量改view尺寸（向布局报告）
	 */
	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
	{
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);

//		 int tW = 400;
//		 int tH = 300;
//		 setMeasuredDimension(tW, tH);
//		
//		 if(mealist!= null){
//				
//			 Rect rect = mealist.onMeasure();
//			 
//			 int height = rect.height();
//			setMeasuredDimension(rect.width(), height);
//		}
		
//		 if(mBitmap != null) {
//				mOldBitmap = mBitmap;
//			}
//			mBitmap = null;
			
//		Log.i("luo_debug", "noteview---"+getMeasuredWidth()+"==hh= "+ getMeasuredHeight());


	}

	@Override
	protected void onSizeChanged(int w, int h, int oldw, int oldh)
	{
		super.onSizeChanged(w, h, oldw, oldh);

	}

	@Override
	protected synchronized void onDraw(Canvas canvas)
	{
		// 11 已经获得wh 
//		int mwid = getWidth();
//		int mheight = getHeight();
		Log.i(TAG, "onDraw------------- ");
		 
		 
		// 22 check参数设置没
		 if (mfilePath == null)
		 {
			 Log.e(TAG, "has not set filePath ");
		 }

		if (!flag_inti) 
		{
			intiEraserParam();

			intiVar(mContext2);
			
			//只是第一次设置
			flag_inti = true ;
		}
		
		// 图片尚未加载完成
//		if(mBitmap == null) {
//			Log.v(TAG, "create Bitmap");
//			mBitmap = Bitmap.createBitmap(getMeasuredWidth(), getMeasuredHeight(),
//					Bitmap.Config.ARGB_4444);
//			mCanvas.setBitmap(mBitmap);
//			if(mOldBitmap != null) {
//				Log.v(TAG, "draw old Bitmap");
//				mCanvas.drawBitmap(mOldBitmap, 0, 0, mBitmapPaint);
//				mOldBitmap.recycle();
//				mOldBitmap = null;
//			}
//			
//			if(mLoadedBitmap != null) {
//				Log.v(TAG, "draw loaded Bitmap");
//				mCanvas.drawBitmap(mLoadedBitmap, 0, 0, mBitmapPaint);
//				mLoadedBitmap.recycle();
//				mLoadedBitmap = null;
//			}
//		}
		
		

		// canvas.drawColor(0xFFAAAAAA);
		canvas.drawColor(Color.parseColor("#00000000"));// 透明
		if(mBitmap == null){
			 Log.e(TAG, "******* mBitmap == null ");
		}else{
			//把记录画下
			canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
		}

		if (mode == MODE_ERASER)
		{
			if (!mLast)
			{
				// mPaint2.setColor(0xff000000);
				mPaint2.setColor(0xffFF6100);
				mPaint2.setStyle(Paint.Style.STROKE);
				mPaint2.setStrokeWidth(2);

				// 会橡皮形状
				canvas.drawRect(mRect.left, mRect.top, mRect.right,
						mRect.bottom, mPaint2);

//				// test把刷新区域显示出来
//				mPaint2.setColor(0xff00FF00);
//				mPaint2.setStyle(Paint.Style.STROKE);
//				mPaint2.setStrokeWidth(1);
//				canvas.drawRect(mRectRefresh, mPaint2);
			}
			else
			{
				/*touchup（）已经有 */
//				invalidate();
			}
		}
		else if (mode == MODE_HIGHLIGHTER)
		{
			//
			canvas.drawPath(mPath, mPaint);
		}
		else
		{
			canvas.drawPath(mPath, mPaint);

			// test把刷新区域显示出来
//			mPaint2.setColor(0xff00FF00);
//			mPaint2.setStyle(Paint.Style.STROKE);
//			mPaint2.setStrokeWidth(1);
//			canvas.drawRect(mRectRefresh, mPaint2);
		}
	}

	/**
	 * set橡皮参数
	 */
	private void intiEraserParam()
	{
		mPixels = new int[2500];
		Arrays.fill(mPixels, 0x00000000);

		// 单位px
		mEraserSize = 30;
	}

	private float mX, mY;
	private static final float TOUCH_TOLERANCE = 4;
	private static final String LOCAL = "noteView";
	/**
	 * 是否初始化
	 * */
	private boolean flag_inti;

	/** 当前是不是橡皮擦模式 **/
	// private boolean isEraser;
	/** 记录橡皮区域 ***/
	private Rect mRect;
	/** 调整橡皮 */
	private int mEraserSize;

	private int[] mPixels;// 用于替换像素的

	/** 记录刷新区域 ***/
	private Rect mRectRefresh;
	/** 调整 刷新区域大小 */
	private int mAdjustment;
	private int mPenWidth = PEN_WID_4;
	/**
	 * 记录画笔起始位置（荧光笔）
	 */
	private float mX_Begin;
	private float mY_Begin;
	
	private NoteView.MeasureListener mealist;
	
	/**
	 * true ===可以写笔记
	 * 
	 */
	private boolean isInPenMode;
	private boolean needSave;
//	private Bitmap mOldBitmap;
	/**
	 * 如果先按清空，进入铅笔模式，铅笔颜色还没有设置采用默认颜色
	 */
	private int mdefaultColor = Color.parseColor("#FFFFFFFF");//默认颜色

	private void touch_start(float x, float y)
	{
		mPath.reset();
		mRect.set(0, 0, 0, 0);
		mLast = false;

		// 非橡皮模式才画线path
		if (mode != MODE_ERASER)
		{
			mPath.moveTo(x, y);
		}
		Log.i(TAG + "draw", "touch_start===" + x + "--" + y);
		mX = x;
		mY = y;

		mX_Begin = x;
		mY_Begin = y;

		// ////更新
		// int AREA_RANGE = 100;// 预设 ?<0
		mRectRefresh.top = (int) (y - mAdjustment);
		mRectRefresh.left = (int) (x - mAdjustment);
		mRectRefresh.right = mRectRefresh.left + 2 * mAdjustment;
		mRectRefresh.bottom = mRectRefresh.top + 2 * mAdjustment;

	}

	private void touch_move(float x, float y)
	{
		float dx = Math.abs(x - mX);
		float dy = Math.abs(y - mY);

		mRectRefresh.top = Math.min((int) (mY - 1), (int) (y - 1));
		mRectRefresh.left = Math.min((int) (mX - 1), (int) (x - 1));
		mRectRefresh.right = Math.max((int) (mX + 1), (int) (x + 1));
		mRectRefresh.bottom = Math.max((int) (mY + 1), (int) (y + 1));
		// 微调
		mRectRefresh.top = mRectRefresh.top - 2 * mAdjustment;
		mRectRefresh.left = mRectRefresh.left - 2 * mAdjustment;
		if (mRectRefresh.top < 0)
		{
			mRectRefresh.top = 0;
		}
		if (mRectRefresh.left < 0)
		{
			mRectRefresh.left = 0;
		}
		mRectRefresh.right = mRectRefresh.right + 2 * mAdjustment;
		mRectRefresh.bottom = mRectRefresh.bottom + 2 * mAdjustment;

		Log.i(TAG + "draw", "touch_move===" + mRectRefresh.left + ","
				+ mRectRefresh.top + "," + mRectRefresh.right + ","
				+ mRectRefresh.bottom);

		// iffffffffffffffffffff
		if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE)
		{
			float x1 = (x + mX) / 2;
			float y1 = (y + mY) / 2;

			if (mode == MODE_PENCIL)
			{
				mPath.quadTo(mX, mY, x1, y1);
				// mPath.rQuadTo(mX, mY, (x + mX) / 2, (y + mY) / 2);
				// mPath.lineTo(mY, mY);

			}
			else if (mode == MODE_HIGHLIGHTER)
			{
				mPath.reset();
				mPath.moveTo(mX_Begin, mY_Begin);
				mPath.lineTo(x, y);

			}
			else if (mode == MODE_ERASER)
			{
				// 调整
				// mRectRefresh.top = mRect.top - adjustment;
				// mRectRefresh.left = mRect.left - adjustment;
				// mRectRefresh.right = mRect.right + adjustment;
				// mRectRefresh.bottom = mRect.bottom + adjustment;

				mRect.set(0, 0, 0, 0);
				// mRect.top = Math.min((int) Math.floor(mY - mEraserSize),
				// (int) Math.floor(y1 + mEraserSize));// Math.min(mRect.top,
				// // (int)Math.floor(ty-10)) ;
				// mRect.left = Math.min((int) Math.floor(mX - mEraserSize),
				// (int) Math.floor(x1 - mEraserSize));
				// mRect.top = mRect.top - 50;
				mRect.top = Math
						.min((int) Math.floor(mY), (int) Math.floor(y1))
						- -mEraserSize;// Math.min(mRect.top,
				mRect.left = Math.min((int) Math.floor(mX), (int) Math
						.floor(x1))
						- mEraserSize;
				mRect.top = mRect.top - 50;
				if (mRect.left < 0)
				{
					mRect.left = 0;
				}
				if (mRect.top < 0)
				{
					mRect.top = 0;
				}
				mRect.right = mRect.left + mEraserSize;
				mRect.bottom = mRect.top + mEraserSize;

				// 替换某区域像素
				// 20111121，边缘地方需修正范围,否则异常！
				int width_area = mEraserSize;
				int height_area = mEraserSize;
				if ((mRect.left + width_area) > getWidth())
				{
					width_area = getWidth() - mRect.left;
					if (width_area < 0)
					{
						width_area = 0;
					}
				}
				if ((mRect.top + height_area) > getHeight())
				{
					height_area = getHeight() - mRect.top;
					if (height_area < 0)
					{
						height_area = 0;
					}
				}
				mBitmap.setPixels(mPixels, 0, mEraserSize, mRect.left,
						mRect.top, width_area, height_area);
			}

			mX = x;
			mY = y;
			Log.i(TAG + "draw", "touch_move>>" + x + "--" + y);

		} // end if
	}

	private void touch_up()
	{
		Log.i(TAG + "draw", "touch_up===" + mX + "--" + mY);

		// if (!isEraser)
		if (mode == MODE_PENCIL)
		{
			mPath.lineTo(mX, mY);
			// commit the path to our offscreen
			mCanvas.drawPath(mPath, mPaint);
			// kill this so we don't double draw
			mPath.reset();

		}
		else if (mode == MODE_HIGHLIGHTER)
		{
			mPath.reset();
			mPath.moveTo(mX_Begin, mY_Begin);
			mPath.lineTo(mX, mY);
			mCanvas.drawPath(mPath, mPaint);

			mPath.reset();
		}
		else
		{
			mLast = true;
		}

	}

	@Override
	public boolean dispatchTouchEvent(MotionEvent event)
	{
		return super.dispatchTouchEvent(event);
	}
	
	
	/**
	 * 
	 */
	@Override
	public boolean onTouchEvent(MotionEvent event)
	{
		Log.i(GUitl.Log_TAG, LOCAL +"---onTouchEvent enter");
//		isInPenMode = false;
		final boolean res = true;
		
		// 非笔记 模式
		if (!isInPenMode)
		{
			Log.i(GUitl.Log_TAG, LOCAL +"---onTouchEvent res =="+false);
			return false;
		}
        
		needSave = true;
        
		float x = event.getX();
		float y = event.getY();
		 Log.i("note_view", "x==" + x + ",y==" + y);
		// Log.i(TAG, "pcount==" + event.getPointerCount());

		switch (event.getAction())
		{
			case MotionEvent.ACTION_DOWN:
				touch_start(x, y);
				invalidate();
				// invalidate(mRectRefresh);
				break;
			case MotionEvent.ACTION_MOVE:
				touch_move(x, y);
				invalidate();
				// invalidate(mRectRefresh);
				break;
			case MotionEvent.ACTION_UP:
				touch_up();
				invalidate();
				// invalidate(mRectRefresh);
				break;
		}
		
			
		Log.i("luo_debug", "note onTouchEvent =" +res );
		
		Log.i(GUitl.Log_TAG, LOCAL +"---onTouchEvent res =="+res);
		
		return res;
	}

	/**
	 * 获得需保存得笔记
	 * desp：
	 * 
	 * @return
	 */
	public Bitmap getNoteBitmp()
	{
		/*
		 * 1>做为canvas 的背景的bitmap即可
		 * 
		 * 2 自身方法截图 *******
		 */
		// dView4.setDrawingCacheEnabled(true);
		// mBitmap = getDrawingCache();

		return mBitmap;
	}

	/**
	 * 橡皮擦模式
	 */
	public void setPenEraser()
	{
		/*
		 * 1.使用mode实现
		 * 2.不是有mode
		 */
		// mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));

		mode = MODE_ERASER;
	}

	/**
	 * 荧光笔模式
	 */
	public void setPenLight(int pColor)
	{
		// 从橡皮擦模式恢复过来
		mPaint.setXfermode(null);

		mode = MODE_HIGHLIGHTER;
		mPaint.setColor(pColor);

		mPaint.setStrokeWidth(PEN_WID_16);
		mPaint.setAlpha(0x66);//透明度确定！
	}

	/**
	 * 铅笔模式
	 * 
	 * @param pColor
	 *            可以不包含透明度
	 */
	public void setPencilColor(int pColor)
	{
		// 从橡皮擦模式恢复过来
		mPaint.setXfermode(null);
		// isEraser = false;
		mode = MODE_PENCIL;

		// 线帽样式
		// mPaint.setStrokeCap(Paint.Cap.ROUND);
		mPaint.setStrokeWidth(mPenWidth);
		mPaint.setColor(pColor);
		
		mPaint.setAlpha(0xA3);// 确定！
	}
	
	/**
	 * 默认设置
	 * 
	 */
	public void inti(){
		// 从橡皮擦模式恢复过来
		mPaint.setXfermode(null);
		// isEraser = false;
		mode = MODE_PENCIL;

		// 线帽样式
		// mPaint.setStrokeCap(Paint.Cap.ROUND);
		mPaint.setStrokeWidth(mPenWidth);
		mPaint.setColor(GUitl.PENCIL_COLOR);
		mPaint.setAlpha(0xA3);// 确定！
	}
	
	/**
	 * 默认铅笔模式
	 * 
	 */
	private void reset(){
		mPaint.setXfermode(null);
		mode = MODE_PENCIL;
		mPaint.setStrokeWidth(mPenWidth);
		
		//恢复铅笔模式，设置之前的颜色
		//不能用if(color >0){}
		if(mdefaultColor != Color.parseColor("#FFFFFFFF")){
			mPaint.setColor(mdefaultColor);
		}else{
			Log.e(TAG, "******mdefaultColor on set **********");
		}
		mPaint.setAlpha(0xA3);// 确定！
	}
 
	/**
	 * 设置默认颜色 2010702
	 * 
	 * 设置默认颜色 应该和铅笔一致。。。。
	 */
	public void setDefaultColor(int color )
	{
		mdefaultColor = color;
		
	}
	
	/**
	 * desp：清空所有笔记
	 */
	public void cleanAllNote()
	{
		// 释放资源！
		if(mBitmap != null){
			mBitmap.recycle();
			mBitmap = null;
		}

//		if(mOldBitmap != null){			
//			mOldBitmap.recycle();
//			mOldBitmap = null;
//		}
		
		// mSaveFlag = false;
		if(getWidth() <= 0 || getHeight() <= 0){
			
//			Log.i("luo_debug", TAG +"-cleanAllNote---"+getWidth()+"==hh= "+ getHeight());
			return ;
		}
		
		//TODO:20120626,出现高度，宽度为0 错误，原因不明
		mBitmap = Bitmap.createBitmap(getWidth(), getHeight(),
				Bitmap.Config.ARGB_4444);
		mCanvas = new Canvas(mBitmap);

		//20120702 ，清空所有笔记，立即删除磁盘笔记
		needSave = false;
		if(mfilePath != null) {
			new File(mfilePath).delete();
		}	
		
		// 默认模式
		// isEraser = false;// ////1126
		reset();
		
		invalidate();
	}
	
	/**
	 * 测量
	 */
	public void setMeasureListener(MeasureListener tl)
	{
		mealist = tl;
	}

	/**
	 * 
	 *@param flag
	 */
	public void setCanNote(boolean flag)
	{
		isInPenMode  = flag;
	}
	public boolean canNoto()
	{
		return isInPenMode ;
	}
	
	/**
	 * 设置笔记保存路径
	 * 
	 *@param filePath
	 */
	public void setNotePath(String filePath)
	{
		if(needSave && mfilePath != null) {
//			save();
		}else {
			if(mBitmap != null) {
				mBitmap.recycle();
				mBitmap = null;
			}
		}
		
		this.mfilePath = filePath;
		
//		if(flag_inti) {
//			load();
//		}
		
	}

	
	/**
	 * 加载旧的笔记，如果没有，则新创建一张图片
	 */
	public void load() {
		new Thread(new Runnable() {

			@Override
			public void run() {
				loadBitmapBackgroud();
			}
		}).start();
	}
	

	/**
	 * 后台加载旧的笔记，如果没有，则新创建一张图片
	 */
	public void loadBitmapBackgroud() {
		BitmapFactory.Options options = new BitmapFactory.Options();
		options.inSampleSize = 1;// 数字越大读出的图片占用的heap越小
		
		final Bitmap bitmap = BitmapFactory.decodeFile(mfilePath, options);
		if(bitmap != null) {
			post(new Runnable() {
				
				@Override
				public void run() {
					Log.v(TAG, "draw load bitmap");
					if(mBitmap == null) {
						mLoadedBitmap = bitmap;
					} else {
						mCanvas.drawBitmap(bitmap, 0, 0, mBitmapPaint);
						bitmap.recycle();
						invalidate();
					}	
				}
			});
		}		
	}

	public void save()
	{
		Log.v(TAG, "save:" + needSave);
		if(needSave) {
			needSave = false;
			final Bitmap bitmap = mBitmap;
			mBitmap = null;
			final String path = mfilePath;
			mfilePath = null;
			
			new Thread(new Runnable() {
				
				@Override
				public void run() {
					saveBitmapBackgroud(bitmap, path);
				}
			}).start();
		}
		
	}
	
	
	public void saveBitmapBackgroud(Bitmap bitmap, String path) {
		Log.v(TAG, "saveBitmapBackgroud");
		if(bitmap == null || path == null) {
			return;
		}
		
		Log.v(TAG, "File path:" + path);
		
		File file = new File(path);

		if(!file.exists()) {
			try {
				file.createNewFile();
			} catch (IOException e) {
				e.printStackTrace();
				sendErrorMessCreate();
				
				return;
			}
		}

		FileOutputStream fOut = null;
		try {
			fOut = new FileOutputStream(file);
		} catch (FileNotFoundException e) {
			sendErrorMessCreate();
			e.printStackTrace();
		}catch (Exception e) {
			sendErrorMessSave();
		}

		if(!bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut)){
			sendErrorMessSave();
			Log.e("test_luo", "-----merror_save_file------");
		}

		try {
			fOut.flush();
		} catch (IOException e) {
			e.printStackTrace();
			sendErrorMessSave();
		}

		try {
			fOut.close();
		} catch (IOException e) {
			e.printStackTrace();
			sendErrorMessSave();
		}
		
		bitmap.recycle();
	}
	
	

	/**
	 * 
	 */
	private void sendErrorMessSave()
	{
	    Message mes = new Message();
//	    mes.what = R.string.error_file_save;
//		((KnowApplication)mContext2.getApplicationContext()).postMessage(mes);
		
	}

	/**
	 * 
	 */
	private void sendErrorMessCreate()
	{
		  Message mes = new Message();
//		  mes.what = R.string.error_file_create;
//		 ((KnowApplication)mContext2.getApplicationContext()).postMessage(mes);
		
	}



	/**
	 *
	 */
	public static interface MeasureListener{
		
		/**
		 * 获得noteview尺寸
		 *@return
		 */
		Rect onMeasure();
	}

	/**
	 * 
	 */
	public void release()
	{
		if(mBitmap != null && !mBitmap.isRecycled()){
			mBitmap.recycle();
			mBitmap = null;
		}
	}
	
	
	
}
